package com.umeng.analytics.pro;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class am extends y {
    private static final String a = "utdid";
    private static final String b = "android.permission.WRITE_EXTERNAL_STORAGE";
    private static final Pattern c = Pattern.compile("UTDID\">([^<]+)");
    private Context d;

    public am(Context arg2) {
        super("utdid");
        this.d = arg2;
    }

    private String b(String arg4) {
        String v0 = null;
        if (arg4 != null) {
            Matcher v1 = am.c.matcher(((CharSequence) arg4));
            if (v1.find()) {
                v0 = v1.group(1);
            }
        }

        return v0;
    }

    public String f() {
        try {
            return (String) Class.forName("com.ut.device.UTDevice").getMethod("getUtdid", Context.class).invoke(null, this.d);
        } catch (Exception v0) {
            return this.g();
        }
    }

    private String g() {
        String v0_3;
        FileInputStream v2;
        String v1 = null;
        File v0 = this.h();
        if (v0 != null && (v0.exists())) {
            try {
                v2 = new FileInputStream(v0);
            } catch (Exception v0_1) {
                v0_1.printStackTrace();
                return null;
            }

            try {
                return this.b(bw.a(v2));
            } catch (Throwable v0_2) {

            }finally {
                bw.c(v2);
            }
        }

        return v1;
    }

    private File h() {
        File v0 = null;
        if ((bv.a(this.d, "android.permission.WRITE_EXTERNAL_STORAGE")) && (Environment.getExternalStorageState().equals("mounted"))) {
            File v2 = Environment.getExternalStorageDirectory();
            try {
                v0 = new File(v2.getCanonicalPath(), ".UTSystemConfig/Global/Alvin2.xml");
            } catch (Exception v1) {
            }
        }

        return v0;
    }
}

